package com.xjy.headfirst.迭代器;

/**
 * decription:
 *
 * @author 辛纪元
 * @since 2022-07-18
 */

public class DinerMenuIterator implements Iterator {

    MenuItem[] items;

    int position;

    public DinerMenuIterator(MenuItem[] items) {
        this.items = items;
    }

    @Override
    public boolean hasNext() {
        return position >= items.length || items[position] != null;
    }

    @Override
    public MenuItem next() {
        MenuItem item = items[position];
        position = position + 1;
        return item;
    }
}
